#include <stdio.h>
#include <string.h>
#include <stdlib.h>

    char s[11][14];
    int bound[14];
    int bit[14];
    int n;
    int score[11][11];
    int f[11][11][2049];
    
void calc_score(int a, int b)
{
    int st, la, lb, k;
    int max = 0;
    int count;
    la = strlen(s[a]);
    lb = strlen(s[b]);
    for (st=-(lb-1); st<=la-1; st++)
    {
        k = st;
        count = 0;
        while (k<la)
        {
            if (k>=0 && (k-st<lb) && s[b][k-st]==s[a][k]) count++;
            k++;
        }
        if (count>max) max=count;
    }
    score[a][b]=max;
}

main()
{
    int i, j, k, h;
    
    //freopen("b.in", "r", stdin);
    //freopen("b.out", "w", stdout);
    
    // initialize const
    for (i=0; i<=11; i++) {bit[i]=1<<i; bound[i]=bit[i]-1;}
    
    // solve problem
    while (scanf("%d", &n), n>0)
    {
        for (i=0; i<n; i++) scanf("%s", s+i);
        // precalc score;
        for (i=0; i<n; i++)
            for (j=0; j<n; j++) if (i!=j)
                calc_score(i, j);
        // do
        memset(f, -1, sizeof(f));
        for (i=0; i<n; i++)
            f[0][i][bit[i]] = 0;
        for (i=0; i<n-1; i++)
            for (j=0; j<n; j++)
                for (k=0; k<=bound[n]-1; k++) if (f[i][j][k]>=0)
                    for (h=0; h<n; h++) if ((bit[h]&k)==0)
                        if (score[j][h]+f[i][j][k]>f[i+1][h][bit[h]|k])
                            f[i+1][h][bit[h]|k] = score[j][h] + f[i][j][k];
        int ans = 0;
        for (i=0; i<n; i++)
            if (f[n-1][i][bound[n]] > ans)
                ans = f[n-1][i][bound[n]];
        printf("%d\n", ans);
    }
    return 0;
}

